﻿using System;
using System.Configuration;
using System.Security;
using System.Web.Security;

/// <summary>
/// Repository for BalloonShop configuration settings
/// </summary>
public static class ElegantFoodConfiguration
{
	// Caches the connection string
	private static string dbConnectionString;
	// Caches the data provider name 
	private static string dbProviderName;
	// Store the number of products frontend per page
	private readonly static int productsFrontPerPage;
	// Store the product frontend description length for product lists
	private readonly static int productFrontDescriptionLength;
	// Store the number of products backend per page
	private readonly static int productsBackPerPage;
	// Store the product backend description length for product lists
	private readonly static int productBackDescriptionLength;
	// Store the name of your shop
	private readonly static string siteName;

	static ElegantFoodConfiguration()
	{
		dbConnectionString = ConfigurationManager.ConnectionStrings["ElegantFoodConnectionString"].ConnectionString;
		dbProviderName = ConfigurationManager.ConnectionStrings["ElegantFoodConnectionString"].ProviderName;
		productsFrontPerPage = System.Int32.Parse(ConfigurationManager.AppSettings["ProductsFrontPerPage"]);
		productFrontDescriptionLength = System.Int32.Parse(ConfigurationManager.AppSettings["ProductFrontDescriptionLength"]);
		productsBackPerPage = System.Int32.Parse(ConfigurationManager.AppSettings["ProductsBackPerPage"]);
		productBackDescriptionLength = System.Int32.Parse(ConfigurationManager.AppSettings["ProductBackDescriptionLength"]);
		siteName = ConfigurationManager.AppSettings["SiteName"];
	}

	// Returns the connection string for the BalloonShop database
	public static string DbConnectionString
	{
		get
		{
			return dbConnectionString;
		}
	}

	// Returns the data provider name
	public static string DbProviderName
	{
		get
		{
			return dbProviderName;
		}
	}

	// Returns the address of the mail server
	public static string MailServer
	{
		get
		{
			return ConfigurationManager.AppSettings["MailServer"];
		}
	}

	// Returns the mail server port
	public static int MailServerPort
	{
		get
		{
			return Int32.Parse(ConfigurationManager.AppSettings["MailServerPort"]);
		}
	}

	// Returns the email username
	public static string MailUser
	{
		get
		{
			return ConfigurationManager.AppSettings["MailUser"];
		}
	}

	// Returns the email password
	public static string MailPassword
	{
		get
		{
			return ConfigurationManager.AppSettings["MailPassword"];
		}
	}

	// Returns the email password
	public static string MailFrom
	{
		get
		{
			return ConfigurationManager.AppSettings["MailFrom"];
		}
	}

	// Send error log emails?
	public static bool EnableErrorLogMail
	{
		get
		{
			return bool.Parse(ConfigurationManager.AppSettings["EnableErrorLogMail"]);
		}
	}

	// Returns the email address where to send error reports
	public static string ErrorLogMail
	{
		get
		{
			return ConfigurationManager.AppSettings["ErrorLogMail"];
		}
	}

	// Returns the maximum number of products frontend to be displayed on a page
	public static int ProductsFrontPerPage
	{
		get
		{
			return productsFrontPerPage;
		}
	}

	// Returns the length of product frontend descriptions in products lists
	public static int ProductFrontDescriptionLength
	{
		get
		{
			return productFrontDescriptionLength;
		}
	}

	// Returns the maximum number of products backend to be displayed on a page
	public static int ProductsBackPerPage
	{
		get
		{
			return productsBackPerPage;
		}
	}

	// Returns the length of product backend descriptions in products lists
	public static int ProductBackDescriptionLength
	{
		get
		{
			return productBackDescriptionLength;
		}
	}

	// Returns the length of product descriptions in products lists
	public static string SiteName
	{
		get
		{
			return siteName;
		}
	}

	// Returns current login user id
	public static Guid CurrentLoginUserID
	{
		get
		{
			return (Guid)Membership.GetUser().ProviderUserKey;
		}
	}

	// Returns the number of days for shopping cart expiration
	public static int CartPersistDays
	{
		get
		{
			return int.Parse(ConfigurationManager.AppSettings["CartPersistDays"]);
		}
	}

	// Send email invoice or not
	public static bool EnableSendInvoice
	{
		get
		{
			return bool.Parse(ConfigurationManager.AppSettings["EnableSendInvoice"]);
		}
	}
}